<?php
/*------------------------------------------------------------------------
# com_vportfolio - Vportfolio component
# ------------------------------------------------------------------------
# author    Vsmart Extensions
# copyright Copyright (C) 2010 www.vsmart-extensions.com. All Rights Reserved.
# @license - http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
# Websites: http://www.vsmart-extensions.com
# Technical Support:  Forum - http://www.vsmart-extensions.com
-------------------------------------------------------------------------*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
 function truncString($str = "", $len = 150, $more = 'true') {
			if ($str == "") return $str;
			if (is_array($str)) return $str;
			$str = trim($str);
			// if it's les than the size given, then return it
			if (strlen($str) <= $len) return $str;
			// else get that size of text
			$str = substr($str, 0, $len);
			// backtrack to the end of a word
			if ($str != "") {
			  // check to see if there are any spaces left
			  if (!substr_count($str , " ")) {
				if ($more == 'true') $str .= "...";
				return $str;
			  }
			  // backtrack
			  while(strlen($str) && ($str[strlen($str)-1] != " ")) {
				$str = substr($str, 0, -1);
			  }
			  $str = substr($str, 0, -1);
			  if ($more == 'true') $str .= "...";
			  if ($more != 'true' and $more != 'false') $str .= $more;
			}
			return $str;
  }
  function cleanHtml($clean_it) {

	$clean_it = preg_replace('/\r/', ' ', $clean_it);
	$clean_it = preg_replace('/\t/', ' ', $clean_it);
	$clean_it = preg_replace('/\n/', ' ', $clean_it);

	$clean_it= nl2br($clean_it);

// update breaks with a space for text displays in all listings with descriptions
	while (strstr($clean_it, '<br>')) $clean_it = str_replace('<br>', ' ', $clean_it);
	while (strstr($clean_it, '<br />')) $clean_it = str_replace('<br />', ' ', $clean_it);
	while (strstr($clean_it, '<br/>')) $clean_it = str_replace('<br/>', ' ', $clean_it);
	while (strstr($clean_it, '<p>')) $clean_it = str_replace('<p>', ' ', $clean_it);
	while (strstr($clean_it, '</p>')) $clean_it = str_replace('</p>', ' ', $clean_it);

// temporary fix more for reviews than anything else
	while (strstr($clean_it, '<span class="smallText">')) $clean_it = str_replace('<span class="smallText">', ' ', $clean_it);
	while (strstr($clean_it, '</span>')) $clean_it = str_replace('</span>', ' ', $clean_it);

	while (strstr($clean_it, '  ')) $clean_it = str_replace('  ', ' ', $clean_it);

// remove other html code to prevent problems on display of text
	$clean_it = strip_tags($clean_it);
	return $clean_it;
  }
  function displayImage($httpPath, $maxWidth = 120, $maxHeight = 120, $param = ""){
  
  	global $mainframe;
	
	$mosConfig_live_site = $mainframe->getSiteURL();
  	$mosConfig_absolute_path = JPATH_SITE."/";

	$pos = strpos($httpPath, $mosConfig_live_site);
	
	if($pos === false){
		$serverPath = $mosConfig_absolute_path.$httpPath;
	}else{
		$serverPath = str_replace($mosConfig_live_site, $mosConfig_absolute_path, $httpPath);
	}
	
	if(!is_file($serverPath)){ // check if file is not existed
		$serverPath = $mosConfig_absolute_path . $default_no_image_file;
		return false;
	}

	list($imgWidth, $imgHeight, $type, $attr) = getimagesize($serverPath);
	
	// image handle
	
	if($maxWidth < 1) $maxWidth = 120;
	if($maxHeight < 1) $maxHeight = 120;
	
	if( $imgHeight <= ($maxHeight - 15 ) && $imgWidth <= ( $maxWidth - 15 ) ){
		
		$attribute = 'height="' . $imgHeight . '"';
		$attribute = 'width="' . $imgWidth . '"';
						
	}else{
		if($imgWidth >= $imgHeight){
			$attribute = 'width="' . ( $maxWidth - 15 ) . '"';
		}else{
			$attribute = 'height="' . ( $maxHeight - 15 ) . '"';
		}
	}
	
	return  $strImage = '<img src="' . $httpPath . '" border=0 hspace=5 vspace=5 ' . $attribute . ' '.$param.' />';
}
?>